package cn.xjt.other;
import java.lang.ThreadGroup;

/**
 * @author xujiangtao
 * @create 2020-08-03-12:47
 */
public class ThreadGroupTest {
    public static void main(String[] args) {
        ThreadGroup tg = new ThreadGroup("我的线程组");
        myThread m = new myThread();
        Thread t = new Thread(tg,m);        //线程构造的时候，第一个参数可以传递线程组
        Thread t2 = new Thread(m);
        t.interrupt();
        tg.list();
        String tName = t.getThreadGroup().getName();    //获取线程组的名字
        String t2Name = t2.getThreadGroup().getName();
        System.out.println(tName);
        System.out.println(t2Name);
        t.start();
        t2.start();
    }
}
class myThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName());
        }
    }
}
